import {get} from '../utils/request'

const host = 'http://127.0.0.1:8000'
const apiVersion = '/api/v1'
const baseUrl = host + apiVersion

export const getBooks = params => {
  if ('id' in params) {
    return get(`${baseUrl}/books/${params.id}/`, params)
  } else {
    return get(`${baseUrl}/books/`, params)
  }
}

export const getBanners = params => {
  if ('id' in params) {
    return get(`${baseUrl}/banners/${params.id}/`, params)
  } else {
    return get(`${baseUrl}/banners/`, params)
  }
}

export const getHotWords = params => {
  if ('id' in params) {
    return get(`${baseUrl}/hotwords/${params.id}/`, params)
  } else {
    return get(`${baseUrl}/hotwords/`, params)
  }
}

export const getCategories = params => {
  if ('id' in params) {
    return get(`${baseUrl}/categories/${params.id}/`, params)
  } else {
    return get(`${baseUrl}/categories/`, params)
  }
}

export const getAuthors = params => {
  if ('id' in params) {
    return get(`${baseUrl}/authors/${params.id}/`, params)
  } else {
    return get(`${baseUrl}/authors/`, params)
  }
}

export const getPublishers = params => {
  if ('id' in params) {
    return get(`${baseUrl}/publishers/${params.id}/`, params)
  } else {
    return get(`${baseUrl}/publishers/`, params)
  }
}
